#include <iostream>
#include <ctime>
#include <fstream>

    using namespace std;

    void bubbleSort(int list[], int listLengh) {
    while(listLengh--)  {
        bool swapped = false;

        for(int i = 0; i < listLengh; i++){
            if(list[i] > list[i+1]){
                swap(list[i], list[i+1]);
                swapped = true;
            }
        }
            if(swapped == false) break;
        }
    }

    void read_from_file( const char *filename, int a[], int length)
    {   ifstream file(filename);

        for(int i=0; i< length; i++)
            file >> a[i];
    }
    int main()
    {
        const int LEN =5000;
        int zxc[LEN];
        int i[LEN];
        int dayn[LEN];

        read_from_file("m8_sorted.txt ",zxc,LEN);
        unsigned int t_start = clock();
        bubbleSort(zxc,LEN);
        unsigned int t_finish = clock();
        unsigned int t_work = t_finish - t_start;
        cout<<"m8_sorted " << t_work << " milleseconds \n";

        read_from_file("m9_sorted.txt ",i,LEN);
        unsigned int j_start = clock();
        bubbleSort(i,LEN);
        unsigned int j_finish = clock();
        unsigned int j_work = j_finish - j_start;
        cout<<"m9_sorted " << j_work << " milleseconds \n";

        read_from_file("m5_sorted.txt ",dayn,LEN);
        unsigned int  idayn_start = clock();
        bubbleSort(dayn,LEN);
        unsigned int idayn_finish = clock();
        unsigned int idayn_work = idayn_finish - idayn_start;
        cout<<"m5_sorted " << idayn_work << " milleseconds \n";

        return 0;
    }
